package cn.edu.jsu.zjj.model.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CheckUtils {
    public static boolean matchesRegex(String phoneNumber, String email) {
        // 手机号正则表达式
        String phoneRegex = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$";
        // 邮箱正则表达式
        String emailRegex = "^[A-Za-z0-9\\u4e00-\\u9fa5]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$";

        // 测试手机号
        boolean isPhoneValid = matchesPattern(phoneRegex, phoneNumber);
        if (isPhoneValid) {
            System.out.println("手机号格式正确");
        } else {
            System.out.println("手机号格式不正确");
        }

        // 测试邮箱
        boolean isEmailValid = matchesPattern(emailRegex, email);
        if (isEmailValid) {
            System.out.println("邮箱格式正确");
        } else {
            System.out.println("邮箱格式不正确");
        }

        // 返回手机号和邮箱格式是否都正确
        return isPhoneValid && isEmailValid;
    }

    private static boolean matchesPattern(String regex, String input) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(input);
        return matcher.matches();
    }


}
